package com.zjeav.lingjiao.base.tools;

import com.zjeav.lingjiao.base.baseBean.Result;
import com.zjeav.lingjiao.base.listener.CommonListener;
import com.zjeav.lingjiao.base.response.LoginResponse;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class ObservableServiceTool {

    public static void getResult(Observable<Result<? extends Observer>> resultObservable, final int type, final CommonListener listener) {
        resultObservable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<Result>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Result result) {
                        listener.OnSuccess(result,type);
                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.OnFailure(e,type);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
